#include<vector>
using namespace std;

 struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 };

class Solution {
public:
    bool isSymmetric(TreeNode* root) {
        if (root == NULL)
            return true;
        return dfs(root->left, root->right);
    }

    bool dfs(TreeNode*A, TreeNode*B){
        //三个中止条件
        if(A == NULL && B == NULL)
            return true;
        if(A == NULL || B == NULL)
            return false;
        if(A->val != B->val)
            return false;
        return dfs(A->left, B->right) && dfs(A->right, B->left);
    }

};